<style>
    .layui-btn .layui-icon{
        margin-right: 0;
    }
    .layui-form-pane .layui-form-label, .layui-form-pane .layui-input-inline{
        width: auto;
    }
    .view-data{
        height: 36px;
        line-height: 36px;
        display: inline-block;
        padding: 0 20px;
        border-style:solid;
        border-width:1px;
        background-color:#fff;
        border-radius:2px;
        border-color:#e6e6e6;
    }
    .table-body .layui-btn .iconfont{
        font-size: 17px !important;
    }
    .layui-card-body{
        background-color: #fff;
        padding: 10px;
        margin-top: 10px;
        border: 1px solid #e6e6e6;
    }
    .layui-tab-card>.layui-tab-title{
        background-color: #f9f9f9;
        border-bottom: none;
    }
    .layui-tab-content{
        padding: 0;
    }
    .layui-table, .layui-table-view{
        margin: 0;
    }
    .layui-form-item{
        margin-bottom: 0px;
    }
</style>
<div class="layui-form seller-form"  action="" >
    <div class="layui-form-item">
        <div class="layui-inline">
            <button type="button" class="layui-btn layui-btn-sm add-room-class"><i class="layui-icon">&#xe608;</i> 添加分类</button>
        </div>
    </div>
</div>

<div class="table-body" style="padding: 10px;">
    <table id="room_class" lay-filter="room_class"></table>
</div>
<script type="text/html" id="btn">
    <a class="layui-btn layui-btn-xs edit-class" lay-event="edit" >编辑</a>
    <a class="layui-btn layui-btn-xs edit-class layui-bg-red" lay-event="del" >删除</a>
</script>
<script>
    var window_box, table;
    layui.use(['table', 'layer',  'form',  ], function () {
        var layer = layui.layer,
                $ = layui.jquery,
                form = layui.form,
                table = layui.table;

        table.render({
            elem: '#room_class', //指定原始表格元素选择器（推荐id选择器）
            height: 'full-260',
            cellMinWidth: '80',
            page:false,
            limit:100,
            id:'room_class',
            url: "{:url('')}",
            cols: [[ //表头
                {field: 'id',title:'ID',align:'center'},
                {field: 'name', title: '房间编号',align:'center'},
                {field: 'ctime', title: '添加时间',align:'center', templet: function(data){
                    var timestamp4 = new Date(data.ctime*1000);
                    return timestamp4.toLocaleDateString().replace(/\//g, "-") + " " + timestamp4.toTimeString().substr(0, 8); 
                }},
                {fixed: 'right', width:200,title:'操作', align:'center', toolbar: '#btn'}
            ]]
        });
        table.on('tool(room_class)', function(obj){
            var data = obj.data;
            if(obj.event == 'edit') {
                layer.prompt({
                    formType: 3,
                    value: data.name,
                    title: '修改分类名'
                 },function(val, index){
                    $.post('{:url("edit")}', {id: data.id,name: val}, function(res) {
                        if(res.status){
                            layer.msg(res.msg,{time:1300},function(){
                                table.reload('room_class');
                            });
                        }else{
                            layer.msg('更新失败');
                        }
                        layer.close(index);
                    })
                });
            } else if(obj.event=='del') {
                layer.confirm('您确定要取消改分类?', function(){
                    $.ajax({
                        type: 'POST',
                        url: "{:url('del')}",
                        data: {id: data.id},
                        dataType: 'json',
                        success: function (respon) {
                            table.reload('room_class');
                            layer.msg('删除成功');
                        }
                    });
                });
            }
        });
        $('.add-room-class').click(function() {
            layer.prompt({
                    formType: 3,
                    value: '',
                    title: '修改分类名'
                 },function(val, index){
                    $.post('{:url("add")}', {name: val}, function(res) {
                        if(res.status){
                            layer.msg(res.msg,{time:1300},function(){
                                table.reload('room_class');
                            });
                        }else{
                            layer.msg('更新失败');
                        }
                        layer.close(index);
                    })
                });
        });
    });
</script>